package com.palm.core.util.castor;

public class LongCastor implements Castor<Long> {
    public static final LongCastor instance=new LongCastor();
    private LongCastor(){}
    @Override
    public Long cast(Object v) {
        if(v==null){
            return 0L;
        }else if(v instanceof Number){
            return ((Number)v).longValue();
        }else{
            String str = v.toString();
            if(str.isEmpty()||"null".equals(str)||"undefined".equals(str)||"Infinity".equals(str)){
                return 0L;
            }else{
                try {
                    return Long.parseLong(str);
                }catch (Exception e){
                    return 0L;
                }
            }
        }
    }
}
